package orm

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

func Connect_mysql() (*gorm.DB, error) {
	db, err := gorm.Open("mysql", "root:123456@tcp(47.75.175.107:3306)/test?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		return nil, err
	}
	return db, nil
}

func Create_table(db *gorm.DB) error {
	for _, model := range []interface{}{&User{}, &Email{}, &CreditCard{}, &Address{}, &Language{}} {
		if !db.HasTable(model) {
			db.CreateTable(model)
		}
	}

	return db.Error
}
